package org.wlgzs.office_exam_student.listener;

import java.util.Timer;
import java.util.TimerTask;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.wlgzs.office_exam_student.service.office.OfficeConfig;

/**
 * Application Lifecycle Listener implementation class TimerTask
 *
 */
@WebListener
public class TimerTaskListener implements ServletContextListener {

    /**
     * Default constructor. 
     */
    public TimerTaskListener() {
        // TODO Auto-generated constructor stub
    }

	/**
     * @see ServletContextListener#contextDestroyed(ServletContextEvent)
     */
    public void contextDestroyed(ServletContextEvent sce)  { 
         // TODO Auto-generated method stub
    }

	/**
     * @see ServletContextListener#contextInitialized(ServletContextEvent)
     */
    public void contextInitialized(ServletContextEvent sce)  { 
         Timer timer = new Timer(true);
         TimerTask task = new TimerTask() {
			@Override
			public void run() {
				OfficeConfig.clean();
			}
		};
        timer.scheduleAtFixedRate(task, 1000*600, 1000* 3600 * 2);
    }
	
}
